package com.software.demo5;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;


public class DataSource implements InitializingBean, DisposableBean {
    private String url;
    private String userName;
    private String password;


    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public void afterPropertiesSet() throws Exception {

        //类似于DBUtil
        System.out.println(this.url);
        System.out.println(this.userName);
        System.out.println(this.password);
        System.out.println("通过实现接口的方式连接上了数据库");
    }

    public void getConnection() {
        System.out.println("通过配置文件中连接上数据库");
    }

    @PostConstruct
    public void annotationGetConnection() {
        System.out.println("通过注解连接上数据库");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("通过实现接口的方式-断开数据库连接");
    }
    public void shutdown() {
        System.out.println("通过配置文件断开数据库");
    }

    @PreDestroy
    public void annotationShutdown() {
        System.out.println("通过注解方式-断开数据库");
    }
}
